package com.loong.common.rest;


import com.loong.common.enumerate.ResultCode;
import lombok.*;

@Setter
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private boolean success;

    /**
     * 响应的消息内容
     */
    private String message;

    /**
     * 响应的状态码
     */
    private Integer code;

    /**
     * 响应的数据内容
     */
    private T data;

    public static <R> Result success(R data){
        return Result.<R>builder()
                .data(data)
                .code(ResultCode.SUCCESS.getCode())
                .message(ResultCode.SUCCESS.getMessage())
                .success(true)
                .build();
    }
    public static <R> Result.ResultBuilder success(){
        return Result.<R>builder()
                .code(ResultCode.SUCCESS.getCode())
                .message(ResultCode.SUCCESS.getMessage())
                .success(true);
    }
    public static <R> Result.ResultBuilder fail(){
        return Result.<R>builder()
                .code(ResultCode.FAIL_DEFAULT.getCode())
                .message(ResultCode.FAIL_DEFAULT.getMessage())
                .success(false);
    }
    public  static <R> Result fail(R data){
        return Result.<R>builder()
                .data(data)
                .code(ResultCode.FAIL_DEFAULT.getCode())
                .message(ResultCode.FAIL_DEFAULT.getMessage())
                .success(false)
                .build();
    }
    public  static <R> Result fail(String message){
        return Result.<R>builder()
                .code(ResultCode.FAIL_DEFAULT.getCode())
                .message(message)
                .success(false)
                .build();
    }
    public  static <R> Result fail(R data,String message,ResultCode resultCode){
        return Result.<R>builder()
                .data(data)
                .code(resultCode.getCode())
                .message(message)
                .success(false)
                .build();
    }
    public  static <R> Result fail(ResultCode resultCode){
        return Result.<R>builder()
                .code(resultCode.getCode())
                .message(resultCode.getMessage())
                .success(false)
                .build();
    }
}
